package cn.xopencode.oss.rpc.permission;

import cn.xopencode.common.framework.vo.CommonResult;
import cn.xopencode.oss.manager.permission.ResourceManager;
import cn.xopencode.oss.rpc.permission.dto.ResourceCreateDTO;
import cn.xopencode.oss.rpc.permission.dto.ResourceUpdateDTO;
import cn.xopencode.oss.rpc.permission.vo.ResourceTreeNodeVO;
import cn.xopencode.oss.rpc.permission.vo.ResourceVO;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Collection;
import java.util.List;

import static cn.xopencode.common.framework.vo.CommonResult.success;

/**
* 资源 Rpc 实现类
*/
@DubboService(version = "${dubbo.provider.ResourceRpc.version}")
public class ResourceRpcImpl implements ResourceRpc {

    @Autowired
    private ResourceManager resourceManager;

    @Override
    public CommonResult<String> createResource(ResourceCreateDTO createDTO) {
        return success(resourceManager.createResource(createDTO));
    }

    @Override
    public CommonResult<Boolean> updateResource(ResourceUpdateDTO updateDTO) {
        resourceManager.updateResource(updateDTO);
        return success(true);
    }

    @Override
    public CommonResult<Boolean> deleteResource(String resourceId) {
        resourceManager.deleteResource(resourceId);
        return success(true);
    }

    @Override
    public CommonResult<ResourceVO> getResource(String resourceId) {
        return success(resourceManager.getResource(resourceId));
    }

    @Override
    public CommonResult<List<ResourceVO>> listResources() {
        return success(resourceManager.listResources());
    }

    @Override
    public CommonResult<List<ResourceVO>> listResources(List<String> resourceIds) {
        return success(resourceManager.listResources(resourceIds));
    }

    @Override
    public CommonResult<List<ResourceVO>> listPositionResource(Collection<String> positionIds, Integer type) {
        return success(resourceManager.listPositionResources(positionIds, type));
    }

    @Override
    public CommonResult<List<ResourceTreeNodeVO>> treeResource() {
        return success(resourceManager.treeResource());
    }

}
